package com.dm.script.mongo;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 * @Author maochuang.li
 *
 * @Email itdreamlmc@163.com
 *
 * @Date Create in 11:47 2017/10/15 0015
 */
@Service
public class MongoService {
    @Autowired
    private MongoTemplate mongoTemplate;


    public void testInsert(JSONObject dataJson) {
        mongoTemplate.insert(dataJson);
    }

    public List<JSONObject> testFind(Query query) {
        List<JSONObject> jsonObjects = mongoTemplate.find(query, JSONObject.class);
        return jsonObjects;
    }
}
